﻿using csLTDMC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZeroBug.EasyFlow.Motion;

namespace Kimd.DMCEtherCard
{
    public class DMCEtherCardPdoOperator : IPdo
    {
        private bool _isErr;
        private string _lastError;
        public bool IsError
        {
            get { return _isErr; }  
        }
        public string LastError
        {
            get { return _lastError; }
            set { _lastError = value; }
        }

        public bool CheckApiResult(short rtn, string errMessage)
        {
            if (rtn != 0)
            {
                _isErr = true;
                _lastError = errMessage;
                return false;
            }
            return true;
        }
        public void ReadPdoData(ushort CardNo, ushort PortNum, ushort address, ushort DataLen, ref int Value)
        {
            CheckApiResult(LTDMC.nmc_read_txpdo_extra(CardNo, PortNum, address, DataLen, ref Value), "读取PDO数据失败!");
        }

        public void WritePdoData(ushort CardNo, ushort PortNum, ushort address, ushort DataLen, int Value)
        {
            CheckApiResult(LTDMC.nmc_write_rxpdo_extra(CardNo, PortNum, address, DataLen, Value), "写入PDO数据失败!");
        }
    }
}
